package java113.project.util;

/*
* This class is used as a tool to track security related exceptions generated from
* our code that is application (business rule) specific; meaning, these are not the generic
* exceptions thrown by the Java security framework but rather exceptions that we are
* have declared security violations in our code; perhaps, one might think, assertions
* are a better solution for this type of validation; while assertions can provide similar functionality,
* most programming languages provide the option to either disable assertions at runtime or
* remove the assertions completely at compile time thereby defeating the secure conventions
* that we might have put in the code
 */

/**
 *
 * @author DocV
 */
public class DocVsSecurityException extends Exception {

    public static int INPUT_FAIL  = 0;
    public static int OUTPUT_FAIL = 1;
    private int       m_iFailType;
    private String    m_strVariableName, m_strVariableValue;

    public
    DocVsSecurityException( String strInMessage, int iInFail, String strInName,
                         boolean blIn ) {
        super( strInMessage );
        this.m_iFailType        = iInFail;
        this.m_strVariableName  = strInName;
        this.m_strVariableValue = String.valueOf( blIn );
    }

    public
    DocVsSecurityException( String strInMessage, int iInFail, String strInName,
                         byte bIn ) {
        super( strInMessage );
        this.m_iFailType        = iInFail;
        this.m_strVariableName  = strInName;
        this.m_strVariableValue = String.valueOf( bIn );
    }

    public
    DocVsSecurityException( String strInMessage, int iInFail, String strInName,
                         char cIn ) {
        super( strInMessage );
        this.m_iFailType        = iInFail;
        this.m_strVariableName  = strInName;
        this.m_strVariableValue = String.valueOf( cIn );
    }

    public
    DocVsSecurityException( String strInMessage, int iInFail, String strInName,
                         double dIn ) {
        super( strInMessage );
        this.m_iFailType        = iInFail;
        this.m_strVariableName  = strInName;
        this.m_strVariableValue = String.valueOf( dIn );
    }

    public
    DocVsSecurityException( String strInMessage, int iInFail, String strInName,
                         float fIn ) {
        super( strInMessage );
        this.m_iFailType        = iInFail;
        this.m_strVariableName  = strInName;
        this.m_strVariableValue = String.valueOf( fIn );
    }

    public
    DocVsSecurityException( String strInMessage, int iInFail, String strInName,
                         int iIn ) {
        super( strInMessage );
        this.m_iFailType        = iInFail;
        this.m_strVariableName  = strInName;
        this.m_strVariableValue = String.valueOf( iIn );
    }

    public
    DocVsSecurityException( String strInMessage, int iInFail, String strInName,
                         long lIn ) {
        super( strInMessage );
        this.m_iFailType        = iInFail;
        this.m_strVariableName  = strInName;
        this.m_strVariableValue = String.valueOf( lIn );
    }

    public
    DocVsSecurityException( String strInMessage, int iInFail, String strInName,
                         Object oIn ) {
        super( strInMessage );
        this.m_iFailType       = iInFail;
        this.m_strVariableName = strInName;

        if ( oIn != null ) {
            this.m_strVariableValue = oIn.toString();
        } else {
            this.m_strVariableValue = null;
        }
    }

    public
    DocVsSecurityException( String strInMessage, int iInFail, String strInName,
                         short sIn ) {
        super( strInMessage );
        this.m_iFailType        = iInFail;
        this.m_strVariableName  = strInName;
        this.m_strVariableValue = String.valueOf( sIn );
    }

    public int getFailType() {
        return this.m_iFailType;
    }

    public String getVariableName() {
        return this.m_strVariableName;
    }

    public String getVariableValue() {
        return this.m_strVariableValue;
    }

    @Override
    public String toString() {
        String strOut = "";

        strOut = System.getProperty( "line.separator" );
        strOut += this.getMessage();
        strOut += System.getProperty( "line.separator" );

        if ( this.m_iFailType == OUTPUT_FAIL ) {
            strOut += "Failure in:  OUTPUT ";
        } else {
            strOut += "Failure in:  INPUT ";
        }

        strOut += System.getProperty( "line.separator" );
        strOut += "Variable name:  ";
        strOut += this.m_strVariableName;
        strOut += System.getProperty( "line.separator" );
        strOut += "Variable value:  ";
        strOut += this.m_strVariableValue;
        strOut += System.getProperty( "line.separator" );

        return strOut;
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
